//
//  RCMerchantDetailTrafficDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-9-10.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMerchantDetailTrafficDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSArray+EX.h"

@implementation RCMerchantDetailTrafficItem

@synthesize title = _title;
@synthesize content = _content;
@synthesize type = _type;
- (id) initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        self.title = [dic stringValueForKey:@"title" defaultValue:nil operation:NSStringOperationTypeNone];
        self.content = [dic stringValueForKey:@"content" defaultValue:nil operation:NSStringOperationTypeNone];
        if ([self.title isEqualToString:@"营业时间"]) {
            self.type = kMerchantDetailTrafficType_Time;
        }else if([self.title isEqualToString:@"公交信息"]){
            self.type = kMerchantDetailTrafficType_Traffic;
        }else if([self.title isEqualToString:@"餐厅特色"]){
            self.type = kMerchantDetailTrafficType_Character;
        }else if([self.title isEqualToString:@"餐厅氛围"]){
            self.type = kMerchantDetailTrafficType_Atmosphere;
        }
        
    }
    return self;
}

- (void) dealloc
{
    self.title = nil;
    self.content = nil;
    
    [super dealloc];
}

@end

@implementation RCMerchantDetailTrafficDataModel

@synthesize itemListArray = _itemListArray;

-(id)init{
    self = [super init];
    if (self) {
        _itemListArray = nil;
    }
    return self;
}

-(void)dealloc{
    self.itemListArray = nil;
    [super dealloc];
}


+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    NSArray *dictArray = [data arrayValueForKey:@"data" defaultValue:nil];
    if (nil == dictArray) {
        return nil;
    }
    RCMerchantDetailTrafficDataModel *retObject = nil;
    retObject = [[RCMerchantDetailTrafficDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    NSMutableArray *itemTempArray = [[NSMutableArray alloc]init];
    for (int i = 0; i < [dictArray count]; i++) {
        NSDictionary *itemDict = [dictArray safeObjectAtIndex:i];
        if (nil == itemDict) {
            continue;
        }
        RCMerchantDetailTrafficItem *item = [[RCMerchantDetailTrafficItem alloc]initWithDic:itemDict];
        if (nil == item) {
            continue;
        }
        [itemTempArray addObject:item];
        [item release];
    }
    retObject.itemListArray = [NSArray arrayWithArray:itemTempArray];
    [itemTempArray release];
    return [retObject autorelease];
}
@end
